package com.fa4j.system.settings.controller;

import com.fa4j.common.base.model.CommonState;
import com.fa4j.system.settings.SettingsClient;
import com.fa4j.system.settings.model.Settings;
import com.fa4j.system.settings.repository.SettingsRepository;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Hidden
@Tag(name = "系统设置")
@RestController
@RequestMapping("system/settings")
@RequiredArgsConstructor
public class SettingsResource implements SettingsClient {

    private final SettingsRepository settingsRepository;

    @Override
    public String findByCode(String code) {
        return settingsRepository.findByCode(code)
                .filter(s -> s.getState() == CommonState.ENABLE)
                .map(Settings::getSettingsData)
                .orElse(null);
    }
}
